package com.yxjx.duoxue.comment;

import java.util.ArrayList;

import com.yxjx.duoxue.R;
import com.yxjx.duoxue.customview.YxListView;
import com.yxjx.duoxue.datamodel.DMCommentReply;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CommentRespondsListView extends LinearLayout {
	
	private ArrayList<DMCommentReply> mAllData;
	private RespondListAdapter mAdapter;
	private YxListView mCommentRespondsList;
	private View mRoot;

	public CommentRespondsListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mRoot = LayoutInflater.from(context).inflate(R.layout.segment_comment_respond_list, this, true);
		mCommentRespondsList = (YxListView) findViewById(R.id.list);
		mAdapter = new RespondListAdapter();
		mCommentRespondsList.setAdapter(mAdapter);
	}
	
	public void setData(ArrayList<DMCommentReply> data) {
		mAllData = data;
		mAdapter.notifyDataSetChanged();
	}
	
	class RespondListAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return mAllData == null ? 0 : mAllData.size();
		}

		@Override
		public Object getItem(int arg0) {
			return null;
		}

		@Override
		public long getItemId(int arg0) {
			return 0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			View ret;
			if (arg1 == null) {
				ret = LayoutInflater.from(getContext()).inflate(R.layout.item_comment_respond, null);
			} else {
				ret = arg1;
			}
			DMCommentReply reply = mAllData.get(arg0);
			TextView text = (TextView) ret.findViewById(R.id.text);
			text.setText(reply.getReplyText());
			return ret;
		}
	}

}
